#region

using Vin.Extension.Captcha.Constants;
using Vin.Extension.Captcha.Model;
using Vin.Extension.Captcha.Service.Interface;
using Vin.Tool.AspNetCore.Service;
using Vin.Tool.AspNetCore.Singleton;
using Vin.Tool.Core.RandomCategory;

#endregion

namespace Vin.Extension.Captcha.Service.Implement.RandomCode;

public class VinRandomLetterNumberService : VinBaseService, IVinRandomCodeService
{
    private VinCaptchaOption _option => VinApp.GetOption<VinCaptchaOption>();

    public string CreateRandomCode(int length)
    {
        return _option.CaptchaType switch
        {
            CaptchaType.Number => VinRandomCodeConstants.NumberChars.Random(length),
            CaptchaType.Letter => VinRandomCodeConstants.LetterChars.Random(length),
            CaptchaType.LetterNumber => VinRandomCodeConstants.LetterNumberChars.Random(length),
            _ => throw new NotSupportedException("不支持的验证码类型")
        };
    }
}